import { defHttp } from '/@/utils/http/axios';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  list = '/api-weixin/wx/account/list',
  create = '/api-weixin/wx/mp/menu/{0}/createByJson1',
  get = '/api-weixin/wx/mp/menu/{0}/get',
  delete = '/api-weixin/wx/mp/menu/{0}/delete',
  deleteByMenuId = '/api-weixin/wx/mp/menu/{0}/delete/{1}',
  materialList = '/api-weixin/wx/mp/material/{0}/material/list',
  newsList = '/api-weixin/wx/mp/material/{0}/news/list',
  getMaterialInfo = '/api-weixin/wx/mp/material/{0}/news/getMaterialInfo',
}

/**
 * 查询帐户列表
 * @param params
 */
export const getAccountList = (params) => {
  return defHttp.get({ url: Api.list, params });
};

/**
 * 自定义菜单创建
 * @param params
 */
export const createMenu = (appid, params) => {
  const url = stringFormat(Api.create, appid);
  return defHttp.post({ url: url, params }, { isTransformResponse: false });
};

/**
 * 自定义菜单查询
 * @param params
 */
export const getMenuDetail = (appid) => {
  const url = stringFormat(Api.get, appid);
  return defHttp.get({ url: url });
};

/**
 * 自定义菜单删除
 * @param params
 */
export const deleteMenu = (appid, handleSuccess) => {
  const url = stringFormat(Api.delete, appid);
  return defHttp.delete({ url: url }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 删除个性化菜单
 * @param params
 */
export const deleteMenuByMenuId = (appid, menuid, handleSuccess) => {
  const url = stringFormat(Api.deleteByMenuId, appid, menuid);
  return defHttp.delete({ url: url }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

/**
 * 素材列表
 * @param params
 */
export const getMaterialList = (params) => {
  const url = stringFormat(Api.materialList, params.appid);
  return defHttp.get({ url: url, params });
};

/**
 * 图文列表
 * @param params
 */
export const getNewsList = (params) => {
  const url = stringFormat(Api.newsList, params.appid);
  return defHttp.get({ url: url, params });
};

/**
 * 指定图文
 * @param params
 */
export const getMaterialInfo = (params) => {
  const url = stringFormat(Api.getMaterialInfo, params.appid);
  return defHttp.get({ url: url, params });
};
